package file

import (
	"fmt"
	"io"
	"os"
)

func CopyFile(dstName, srcName string) (written int64, err error) {
	//以读方式打开源文件
	src, err := os.Open(srcName)
	if err != nil {
		fmt.Printf("open %s filed,err:%v", srcName, err)
		return
	}
	defer src.Close()
	//以写|创建的方式打开目标文件
	dst, err := os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE, 0644)
	if err != nil {
		fmt.Printf("open file filed, err:%v", err)
		return
	}
	defer dst.Close()
	return io.Copy(dst, src)
}
